package com.ta.stage.controller;


import com.ta.stage.entity.Serverdb;
import com.ta.stage.result.Result;
import com.ta.stage.service.ServerdbService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/serverdb/")
@Api(tags={"平台服务器数据库 PolicyController"})
public class ServerdbController {

    @Autowired
    private ServerdbService serverdbService;

    @ApiOperation(value = "查询平台服务器数据库")
    @RequestMapping(value = "findServerdb",method = RequestMethod.GET)
    @ResponseBody
    public Result findServerdb(){
        List<Serverdb> serverdbList = serverdbService.list(null);
        return Result.ok(serverdbList);
    }

    @ApiOperation(value = "根据id查询平台服务器数据库")
    @GetMapping("getServerdb/{id}")
    public Result getServerdb(@PathVariable Long id){
        Serverdb serverdb = serverdbService.getById(id);
        return Result.ok(serverdb);
    }

    @ApiOperation(value = "新增平台服务器数据库")
    @RequestMapping(value = "saveServerdb",method = RequestMethod.POST)
    @ResponseBody
    public Result saveServerdb(@RequestBody Serverdb serverdb){
        boolean save = serverdbService.save(serverdb);
        return save?Result.ok():Result.fail();
    }

//    @ApiOperation(value = "逻辑删除平台服务器数据库")
//    @DeleteMapping("{id}")
//    public Result removeRoleMenu(@PathVariable Long id){
//        boolean flag = deptService.removeById(id);
//        return flag?Result.ok():Result.fail();
//    }

    @ApiOperation(value = "修改平台服务器数据库")
    @PostMapping("updateServerdb")
    public Result updateServerdb(@RequestBody Serverdb serverdb){
        boolean flag = serverdbService.updateById(serverdb);
        return flag?Result.ok():Result.fail();
    }

    @ApiOperation(value = "批量删除平台服务器数据库")
    @DeleteMapping("batchRemoveServerdb")
    public Result batchRemoveServerdb(@RequestBody List<Long> idList){
        serverdbService.removeByIds(idList);
        return Result.ok();
    }

//    @ApiOperation(value = "平台服务器数据库条件查询带分页")
//    @PostMapping("findPagePolicy/{current}/{limit}")
//    public Result findPagePolicy(@PathVariable long current,
//                               @PathVariable long limit,
//                               @RequestBody(required = false) DeptVo deptVo){
//
//        //创建page对象，传递当前页，每页记录数
//        Page<Dept> page = new Page<>(current,limit);
//
//        //构建条件
//        QueryWrapper<Dept> wrapper = new QueryWrapper<>();
//        Integer id = deptVo.getId();
//        String name = deptVo.getName();
//        String charge = deptVo.getCharge();
//        String address = deptVo.getAddress();
//        //条件可能为空
//        if (!StringUtils.isEmpty(id)){
//            wrapper.eq("id",deptVo.getId());
//        }
//        if (!StringUtils.isEmpty(name)){
//            wrapper.like("name",deptVo.getName());
//        }
//        if (!StringUtils.isEmpty(charge)){
//            wrapper.like("charge",deptVo.getCharge());
//        }
//        if (!StringUtils.isEmpty(address)){
//            wrapper.like("address",deptVo.getAddress());
//        }
//        //调用方法实现分页查询
//        Page<Dept> pageDept = deptService.page(page, wrapper);
//        return Result.ok(pageDept);
//    }
}
